from flask import request
from flask_restful import Resource

from database import Database
from users.book.model.Stack import Stack



class GetAllStacks(Resource):
    def get(self):
        db = Database()
        query = "SELECT * FROM stack"
        stacks = db.execute_query(query)
        stacks_json = []

        for stack in stacks:
            stack_obj = Stack(stack[0], stack[1], stack[2], stack[3], stack[4], stack[5], stack[6], stack[7])
            stacks_json.append(stack_obj.to_dict())

        return {"stacks": stacks_json}, 200